<?php
namespace app\index\controller;
use think\Controller;
use think\Db;

class Index extends Controller
{
    public function index($name = 'hh')
    {
        $sql = "select *from account;";
        $result = Db::query($sql);
        foreach ($result as &$item){
            $item['plus'] = 'asdg';
            $item['aa'] = 'asdg';
        }
        return json($result);

    }

    public function hello($name = 'hh')
    {
        $data = Db::name('account')->find();
        $this->assign('result', $data);
        return $this->fetch();
    }

    public function urlget()
    {
        $url = 'http://www.baidu.com';
//初始化一个 cURL 对象
        $ch  = curl_init();
//设置你需要抓取的URL
        curl_setopt($ch, CURLOPT_URL, $url);
// 设置cURL 参数，要求结果保存到字符串中还是输出到屏幕上。
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//是否获得跳转后的页面
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        $data = curl_exec($ch);
        curl_close($ch);
        echo $data;
    }



    public function urlpost()
    {
        $url="http://app.qcjkjg.com/getmyschool";
        $arr_post = array(
            'phone'=>'15550322512'
        );

        $post_data = http_build_query($arr_post);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
}
?>